<!--
 * @Description: 教师list弹窗
 * @Autor: dyx
 * @Date: 2023-02-15 15:45:14
 * @LastEditTime: 2023-02-15 17:23:49
-->
<template>
  <el-dialog
    title="讲师列表"
    :close-on-click-modal="false"
    :visible.sync="visible"
    class="JADP-dialog JADP-dialog_center"
    lock-scroll
    width="70%"
  >
    <el-row class="JADP-common-search-box" :gutter="16">
      <el-form @submit.native.prevent>
        <el-col :span="6">
          <el-form-item label="讲师名称">
            <el-input v-model="query.realname" placeholder="请输入" clearable>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="职称/职务">
            <el-input
              v-model="query.technicaltitle"
              placeholder="请输入"
              clearable
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="search()"
              >查询</el-button
            >
            <el-button icon="el-icon-refresh-right" @click="reset()"
              >重置</el-button
            >
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
    <JADP-table
      v-loading="listLoading"
      :data="list"
      highlight-current-row
      @current-change="handleCurrentChange"
      :row-style="{ cursor: 'pointer' }"
      height="400"
    >
      <el-table-column prop="realname" label="姓名" align="left" />
      <el-table-column prop="gender" label="性别" width="0" align="left">
        <template v-slot="{ row }">
          {{ getDict("sex", row.gender) }}
        </template>
      </el-table-column>
      <el-table-column prop="birthday" label="出生年月" align="left" />
      <el-table-column
        prop="certificatesnumber"
        label="身份证号码"
        align="left"
        width="200"
      />
      <el-table-column prop="education" label="学历" width="0" align="left">
        <template v-slot="{ row }">
          {{ getDict("Education", row.education) }}
        </template>
      </el-table-column>
      <el-table-column
        prop="major"
        label="所学专业"
        align="left"
        show-overflow-tooltip
      />
      <el-table-column
        prop="technicaltitle"
        label="职称/职务"
        align="left"
        show-overflow-tooltip
      />
      <el-table-column
        prop="xzjob"
        label="职称专业"
        align="left"
        show-overflow-tooltip
      />
      <el-table-column
        prop="teachingsubjects"
        label="所任课程"
        align="left"
        show-overflow-tooltip
      />
      <el-table-column
        prop="fixedphone"
        label="安全培训教师岗位证书编号"
        width="200"
        align="left"
        show-overflow-tooltip
      />
    </JADP-table>
    <pagination
      :total="total"
      :page.sync="listQuery.currentPage"
      :limit.sync="listQuery.pageSize"
      @pagination="initData"
    />

    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" @click="dataFormSubmit">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import request from "@/utils/request";
export default {
  name: "",
  data() {
    return {
      currentRow: {},
      query: {
        realname: "",
        technicaltitle: ""
      },
      list: [],
      visible: false,
      listLoading: false,
      total: 0,
      listQuery: {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: "creatortime"
      }
    };
  },
  created() {
    this.initData();
  },
  methods: {
    handleCurrentChange(val) {
      this.currentRow = val;
      console.log(this.currentRow, 456);
    },
    initData() {
      this.listLoading = true;
      let _query = {
        ...this.listQuery,
        ...this.query,
        organizeId:this.$store.getters.organizeId
      };
      request({
        url: `/api/teachersManage/Xy_ks_teachers/getList`,
        method: "post",
        data: _query
      }).then(res => {
        this.list = res.data.list;
        this.total = res.data.pagination.total;
        this.listLoading = false;
      });
    },

    dataFormSubmit() {
      if (this.currentRow.id) {
        this.$emit("currentRow", this.currentRow.id, this.currentRow.realname);
        this.visible = false;
      } else {
        this.$message.warning("请至少选择一个讲师！");
      }
    },

    search() {
      this.listQuery = {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: ""
      };
      this.initData();
    },
    reset() {
      for (let key in this.query) {
        this.query[key] = undefined;
      }
      this.listQuery = {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: ""
      };
      this.initData();
    }
  }
};
</script>
<style scoped lang="scss"></style>
